package com.pingan.agentbank.aaos.testme;


import com.alibaba.fastjson.JSONObject;
import com.pingan.agentbank.aaos.pojo.ApproFileInfo;
import com.pingan.agentbank.aaos.pojo.ApproLineInfo;
import com.pingan.agentbank.aaos.service.ApproFileDaoService;
import com.pingan.agentbank.aaos.service.ApproLineDaoService;
import com.pingan.agentbank.aaos.task.DBCleanTask;
import com.pingan.vframe.Controller;
import com.pingan.vframe.SystemConfig;
import com.pingan.vframe.beans.Injector;
import com.pingan.vframe.db.DBIterator;
import com.pingan.vframe.db.DBTransaction;
import com.pingan.vframe.sdo.ServiceData;
import com.pingan.vframe.util.*;
import org.junit.Test;

import java.io.*;
import java.util.ArrayList;
import java.util.List;

public class Test3 {



    @Test
    public void method1() throws Exception {
        String str = "你好";
        byte[] bytes = str.getBytes("gbk");
        OutputStream outputStream = new FileOutputStream("D:\\temp\\1.txt");

        System.out.println(bytes.length);
        outputStream.write(bytes);
        outputStream.close();
    }

    //读空行,会读到空字符串
    @Test
    public void method2() throws Exception {
        InputStream inputStream = new FileInputStream("D:\\temp\\1.txt");
        InputStreamReader isr = new InputStreamReader(inputStream,"gbk");
        BufferedReader bufferedReader = new BufferedReader(isr);
        String string = "";
        int count = 0;
        while (!StringUtil.isEmpty(string = bufferedReader.readLine())){
            count++;
            System.out.println(count + "-->|" + string+"|");
        }
    }

    /*
    * 开发无锡农商时，用vframe自带的JSON取消JSON中的换行符
    * */
    @Test
    public void method3(){

        ServiceData serviceData = new ServiceData();
        serviceData.putString("name","zhangsan");
        serviceData.putString("age","25");
        serviceData.putString("sex","男");

        System.out.println(JSON.fromServiceData(serviceData, JSONCaseType.DEFAULT));
        String str = com.pingan.vframe.util.JSON.fromServiceData(serviceData, JSONCaseType.DEFAULT);
        String newStr = str.replace("\n","");
        System.out.println(newStr);
    }

    @Test
    public void method4() throws UnsupportedEncodingException {
        String str = "你好";
        byte[] bytes = str.getBytes("utf8");
        System.out.println(bytes.length);
    }

    @Test
    public void method5(){
        GBKProperties props = SystemConfig.getInstance().getProperties("com.WRCB");
        String value = props.getProperty("sourDir");
        System.out.println(value);
    }

    @Test
    public void method6(){
        //System.out.println(new Date().getTime());
        ServiceData serviceData = new ServiceData();
        serviceData.putString("name","tom");
        serviceData.putString("sex","男");
        //serviceData.putInt("age",20);
        serviceData.putString("age",null);
        String str = JSON.fromServiceData(serviceData, JSONCaseType.DEFAULT);
        str = str.replace("\n","");
        System.out.println(str);
    }

    @Test
    public void method7(){
        Injector injector = Controller.getInstance().getInjector();
        DBCleanTask clusteDaoService = injector.getBean(DBCleanTask.class);
        DBCleanTask clusteDaoService1 = injector.getBean(DBCleanTask.class);
        System.out.println(clusteDaoService == clusteDaoService1);

        /*int count = clusteDaoService.updateClusteInfoByTaskNameAndFlag("main","1", JaDateTime.now(),"0","inDb");
        DBTransaction tran = DBTransaction.get();
        tran.commitAndResume();
        System.out.println(count);*/
    }

    @Test
    public void method8(){

        //String line = "{\"send_addr_type\":\"2\",\"audit_result\":\"12\",\"out_apply_no\":\"284cc91a08\",\"chinese_name\":\"颜勇\",\"sex\":\"M\",\"birth_date\":\"20130129\",\"owner_name\":\"YAN YONG\",\"mobile\":\"13816951812\",\"global_type\":\"1\",\"global_id\":\"610204201301298316\",\"global_eff_enddate\":\"20991231\",\"marital_status\":\"9\",\"education\":\"03\",\"address1\":\"上海市浦东新区住宅地址１１２\",\"address2\":\"上海市浦东新区住宅地址２１２\",\"address3\":\"上海市浦东新区住宅地址３１２\",\"address4\":\"上海市浦东新区住宅地址412\",\"postcode\":\"223002\",\"residential_type\":\"2\",\"companyname\":\"平安测试批核\",\"departname\":\"审批部门\",\"post\":\"职务\",\"employer_add1\":\"单位地址１１２\",\"employer_add2\":\"单位地址２１２\",\"employer_add3\":\"单位地址３１２\",\"employer_add4\":\"单位地址412\",\"employer_postcode\":\"223002\",\"employer_phone\":\"545445454748\",\"working_years\":\"1\",\"immidediate_name\":\"日进斗金\",\"immidediate_relation\":\"5\",\"immidediate_mobile\":\"15575447644\",\"other_name\":\"１３３４５３\",\"other_relation\":\"3\",\"other_mobile\":\"19970813345\",\"sales_company_code\":\"920750001\",\"creditcardCategory\":\"G\",\"creditcardType\":\"C\",\"collection_no\":\"R013189040903074518\",\"bar_code\":\"R01318900040308618\",\"affinityCode\":\"0000\",\"campaign_code\":\"WXB00001\",\"giveCardCity \":\"2230\",\"onlineSQFlag\":\"\",\"applicationFlag\":\"0\",\"expand_branch\":\"1005\",\"email\":\"52626227@QQ.COM\",\"country_citizen\":\"156\",\"global_eff_flag\":\"1\",\"issuing_authority\":\"潮州市\",\"children_flag\":\"1\",\"phone_area\":\"0356\",\"home_phone\":\"035659597459\",\"employer_phone_areano\":\"5454\",\"company_type\":\"03\",\"annual_income\":\"2000\",\"ex_working_years\":\"1\",\"car_number\":\"沪D88888\",\"car_brand\":\"奔驰\",\"application_tool\":\"NPA\",\"applytime\":\"\",\"upload_cardtye\":\"\",\"channel_id\":\"PC\",\"expand_source\":\"\",\"monthly_mortgage_payment\":\"10000\",\"reside_add1\":\"户籍地址12\",\"reside_add2\":\"户籍地址22\",\"reside_add3\":\"户籍地址32\",\"reside_add4\":\"户籍地址42\",\"reside_postcode\":\"223002\",\"amount\":\"20000\",\"refuse_code\":\"\",\"payment_limit_type\":\"1\",\"job_code\":\"80000\",\"card_down\":\"\"}";
        String line = "{\"application_no\":\"2019080090007025307\",\"party_no\":\"000700024512\",\"expand_branch\":\"1005\",\"chinese_name\":\"\",\"sex\":\"\",\"birth_date\":\"\",\"owner_name\":\"\",\"mobile\":\"\",\"email\":\"JJJ8@163.COM\",\"country_citizen\":\"156\",\"global_type\":\"\",\"global_id\":\"\",\"global_eff_enddate\":\"\",\"issuing_authority\":\"特殊市县\",\"marital_status\":\"\",\"children_flag\":\"2\",\"education\":\"\",\"home_phome\":\"10127364812\",\"address1\":\"\",\"address2\":\"\",\"address3\":\"\",\"address4\":\"\",\"postcode\":\"243100\",\"residential_type\":\"\",\"companyname\":\"\",\"departname\":\"\",\"post\":\"\",\"employer_add1\":\"\",\"employer_add2\":\"\",\"employer_add3\":\"\",\"employer_add4\":\"\",\"employer_postcode\":\"\",\"employer_phone\":\"\",\"working_years\":\"\",\"ex_working_years\":\"5\",\"immidediate_name\":\"\",\"immidediate_relation\":\"\",\"immidediate_mobile\":\"\",\"other_name\":\"\",\"other_relation\":\"\",\"other_mobile\":\"\",\"mainBillingPostType\":\"1\",\"send_addr_type\":\"\",\"sales_company_code\":\"\",\"application_tool\":\"NPA\",\"applytime\":\"201212\",\"upload_cardtye\":\"3\",\"creditcardCategory\":\"\",\"creditcardType\":\"\",\"collection_no\":\"\",\"bar_code\":\"\",\"source_code\":\"0O\",\"affinityCode\":\"\",\"applicationFlag\":\"\",\"positionname\":\"阳光国际\",\"monthly_mortgage_payment\":\"2300\",\"campaign_code\":\"\",\"giveCardCity\":\"\",\"agentunit\":\"WRCB\",\"reside_years\":\"4\",\"reside_add1\":\"测试户籍地址一\",\"reside_add2\":\"测试户籍地址二\",\"reside_add3\":\"测试户籍地址三\",\"reside_add4\":\"测试户籍地址四\",\"reside_postcode\":\"\",\"job_code\":\"10200\",\"certification_type\":\"仅为中国税收居民\",\"audit_result\":\"\",\"amount\":\"\",\"refuse_code\":\"A09\",\"phone_area\":\"101\",\"employer_phone_areano\":\"010\",\"channel_id\":\"WX\",\"working_state\":\"1\",\"out_apply_no\":\"\",\"onlineSQFlag\":\"\",}\n";
        JSONObject jsonObject = com.alibaba.fastjson.JSON.parseObject(line);
        String value = jsonObject.getString("postcode");
        System.out.println(value);
    }

    @Test
    public void method9() throws Exception {

        BufferedReader bufferedReader1 = new BufferedReader(new InputStreamReader(new FileInputStream("D:/temp/WRCB/testA/RS-WRCB-APPROVAL-20190321-01.txt")));
        BufferedReader bufferedReader2 = new BufferedReader(new InputStreamReader(new FileInputStream("D:/temp/WRCB/testB/RS-WRCB-APPROVAL-20190321-01.txt")));

        while (true){
            String str1 = bufferedReader1.readLine();
            String str2 = bufferedReader2.readLine();
            if (str1==null && str2==null){
                break;
            }
            System.out.println(str1.equals(str2));
        }




    }

    @Test
    public void method10(){

        ServiceData serviceData = new ServiceData();
        serviceData.putString("name",null);
        System.out.println(JSON.fromServiceData(serviceData,JSONCaseType.DEFAULT));

    }

    @Test
    public void method11(){

        String num = null;
        int i = Integer.parseInt(num);
    }

    @Test
    public void method12(){

        Injector injector = Controller.getInstance().getInjector();
        ApproFileDaoService approFileDaoService = injector.getBean(ApproFileDaoService.class);
        ApproFileInfo approFileInfo = new ApproFileInfo();
        approFileInfo.setFilename("ZJKB-APPROVAL-20190402-02.txt");
        approFileDaoService.saveOneApproFileInfo(approFileInfo);
        DBTransaction tran = DBTransaction.get();
        try {
            tran.commitAndResume();

        } catch (Exception e){
            System.err.println(e.getMessage());
        }
    }

    @Test
    public void method13(){

        Injector injector = Controller.getInstance().getInjector();
        ApproLineDaoService approLineDaoService = injector.getBean(ApproLineDaoService.class);
        DBIterator<ApproLineInfo> lineIterator = approLineDaoService.queryByFileId(102001);
        List<ApproLineInfo> idList = new ArrayList<>();
        while (lineIterator.hasNext()){
            idList.add(lineIterator.next());
        }


        for (int i=0;i<idList.size();i++){

            ApproLineInfo approLineInfo = idList.get(i);
            System.out.println(approLineInfo.getOnlineSQFlag().equals(""));

        }
    }




}
